package com.situ.day8;

//Java里面要到类需要import进来，本包的类不需要import，外部包需要import
//特例：java.lang包放很多Java常用类像System、String，这个包下面是不需要导包
import com.situ.day7.Person;
import org.junit.Test;

import java.util.Scanner;

public class StudentManager {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入学生数量：");
        int count = scanner.nextInt();
        Student[] students = new Student[count];
        for (int i = 0; i < students.length; i++) {
            System.out.println("请输入id：");
            int id = scanner.nextInt();
            System.out.println("请输入姓名:");
            String name = scanner.next();
            System.out.println("请输入年龄：");
            int age = scanner.nextInt();
            System.out.println("请输入性别：");
            String gender = scanner.next();
            //每遍历一次构造一个学生对象,然后放到数组里面
            Student student = new Student(id, name, age, gender);
            students[i] = student;
        }
        for (Student student : students) {
            System.out.println(student);
        }

        //如果搜索不到对应信息，打印一个：没有该信息的学生
        while (true) {
            System.out.println("按照id搜索输入1：");
            System.out.println("按照name搜索输入2：");
            System.out.println("按照age搜索输入3：");
            System.out.println("按照gender搜索输入4：");
            System.out.println("退出输入0：");
            int type = scanner.nextInt();
            if (type == 0) {
                System.out.println("退出搜索");
                break;
            }

            //找到了吗？false 初始没有找到
            boolean isFound = false;
            switch (type) {
                case 1:
                    System.out.println("请输入搜索的id值：");
                    int id = scanner.nextInt();
                    for (Student student : students) {
                        if (student.getId() == id) {
                            System.out.println(student);
                            isFound = true;
                        }
                    }
                    break;
                case 2:
                    System.out.println("请输入搜索的name值：");
                    String name = scanner.next();
                    for (Student student : students) {
                        if (name.equals(student.getName())) {
                            System.out.println(student);
                            isFound = true;
                        }
                    }
                    break;
            }

            /*if (isFound == false) {
                System.out.println("没有该信息学生");
            }*/
            if (!isFound) {
                System.out.println("没有该信息学生");
            }
        }

        //Unreachable statement
        System.out.println("StudentManager.main");
    }

    @Test
    public void test1() {
        String str1 = "zhansgan";
        String str2 = "zhansgan";
        if (str1.equals(str2)) {
            System.out.println("==");
        } else {
            System.out.println("!=");
        }

        Person person = new Person();
        //person.id = 1;
    }

}
